//
//  CommentModel.swift
//  travelMap
//
//  Created by green on 15/6/30.
//  Copyright (c) 2015年 com.city8. All rights reserved.
//

import JSONHelper

// POI评论
public
class CommentModel: NSObject, Deserializable {
   
    var commentId       : String?               // ID
    var author          : String?               // 评论人
    var authorPicUrl    : NSURL?                // 头像
    var content         : String?               // 评论的内容
    var level           : Int = random()%5+1    // 星级
    var commentTime     : NSDate?               // YYYY-MM-dd HH:mm:ss
    
    var authorPhotoInfo: PhotoInfo?
    
    override init() { }
    
    required public init(data : [String:AnyObject]) {
        
        commentId      <-- data["id"]
        author         <-- data["nickName"]
        authorPicUrl   <-- data["headPhoto"]
        content        <-- data["content"]
        level          <-- data["level"]
        commentTime    <-- (data["createTime"],"yyyy-MM-dd HH:mm:ss")
        
        if let authorPicUrl=authorPicUrl {
            
            authorPhotoInfo = PhotoInfo(sourceImageURL: authorPicUrl)
        }
    }
    
    override public var description: String {
        
        get {
            
            return "commentId:\(commentId) \n author:\(author) \n authorPicUrl:\(authorPicUrl) \n content:\(content) \n level:\(level) \n commentTime:\(commentTime) \n  --------------------------------------------------------------------- \n "
        }
    }
    
    // MARK: - 重写比较方法
    
    override public func isEqual(object: AnyObject?) -> Bool {
        
        if let object=object as? CommentModel {
            
            if object.commentId == self.commentId {
                
                return true
            }
        }
        return false
    }
    
    override public var hash: Int {
        
        get {
            
            return (self.commentId == nil ? "" :self.commentId!).hash
        }
    }
    
}
